'''
Created on Aug 23, 2012

@author: petrina
'''

import logging

class Log_manager(object):
    '''
    initializes the logging with loglevel and logfile.
    
    The logging is responsible for writing logging massages to a log-file or to the console
    The standard logging-level is INFO. 
    If the logging-level is None the logger assumes INFO
    If the file is none messages are written to the console.
    '''
    
    DEBUG = logging.DEBUG
    INFO = logging.INFO

    def __init__(self, loglevel=INFO, file = None):
        '''
        Inits the logging for the first time (there should be only one object of this class).
        
        @param loglevel: default is debug (the value None means that the level is set to DEBUG)
        @param file: filepath for the logging, the default is None (if it is None the log-messages are sent to the console)
        '''

        if loglevel is None:
            loglevel=Log_manager.INFO
            
        # init logging-object for console or log-file
        if file is None:
            form = "%(asctime)-15s\t%(name)-5s\t%(levelname)-8s\t%(message)s"
            logging.basicConfig(level=loglevel, format=form)
    
        else:
            form = "%(asctime)-15s %(levelname)s\t(%(filename)s:%(lineno)d) -  %(message)s"
            logging.basicConfig(filename=file, level=loglevel, format=form)
            
        logging.info("Logging Initialized.")